<!DOCTYPE html>
<html lang="en">
	<head>
    	<meta name="layout" content="main_mobile">
        <title>火堆</title>
        <script src="http://res.wx.qq.com/open/js/jweixin-1.0.0.js"></script>
        <script type="text/javascript">
	    wx.config({
	 	    debug: false,  // 开启调试模式,调用的所有api的返回值会在客户端alert出来，若要查看传入的参数，可以在pc端打开，参数信息会通过log打出，仅在pc端时才会打印。
	 	    appId: '${appid}', // 必填，公众号的唯一标识
	 	    timestamp: "${timestamp}", // 必填，生成签名的时间戳
	 	    nonceStr: '${nonceStr}', // 必填，生成签名的随机串
	 	    signature: '${signature}',// 必填，签名，见附录1
	 	    jsApiList: ['checkJsApi' , 'onMenuShareAppMessage' , 'onMenuShareTimeline']
	 	});

	 	wx.ready(function(){
	 		wx.checkJsApi({
	 		    jsApiList: ['onMenuShareAppMessage' , 
	 			 		    'onMenuShareTimeline'
	 		              ], // 需要检测的JS接口列表，所有JS接口列表见附录2,
	 		    success: function(res) {
	 		       //alert('wx.check: '+JSON.stringify(res));
	 		    }
	 		});
	 		//发送给朋友分享功能
	 		wx.onMenuShareAppMessage({
	 		    title: '${user?.nickname}邀请你进入火堆公益众筹，一起助力教育', // 分享标题
	 		    desc: '关注火堆，为教育发声！', // 分享描述
	 		    link: '${shareUrl}', // 分享链接
	 		    imgUrl: '${imgUrl}', // 分享图标
				trigger: function () {
				//alert("点击按钮");
				},
	 		    success: function () { 
	 		        // 用户确认分享后执行的回调函数
	 		        $('.wx-share-box').removeClass('show');
	 		    },
	 		    cancel: function () { 
	 		        // 用户取消分享后执行的回调函数
	 		    	$('.wx-share-box').removeClass('show');
	 		    }
	 		});

	 		//分享到朋友圈
	 		wx.onMenuShareTimeline({
	 		    title: '${user?.nickname}邀请你进入火堆公益众筹，一起助力教育', // 分享标题
	 		    link: '${shareUrl}', // 分享链接
	 		    imgUrl: '${imgUrl}',  // 分享图标
	 		    success: function () { 
	 		        // 用户确认分享后执行的回调函数
	 		    	$('.wx-share-box').removeClass('show');
	 		    },
	 		    cancel: function () { 
	 		        // 用户取消分享后执行的回调函数
	 		    	$('.wx-share-box').removeClass('show');
	 		    }	
	 		});
	 	});
	 	wx.error(function (res) {
			//alert('wx.error: '+JSON.stringify(res));
	    });

	 	function IsPC() 
	 	{ 
	 	var userAgentInfo = navigator.userAgent; 
	 	var Agents = new Array("Android", "iPhone", "SymbianOS", "Windows Phone", "iPad", "iPod"); 
	 	var flag = true; 
	 	for (var v = 0; v < Agents.length; v++) { 
	 	if (userAgentInfo.indexOf(Agents[v]) > 0) { flag = false; break; } 
	 	} 
	 	return flag; 
	 	}


	    
	</script>       
     <link rel="stylesheet" href="${resource(dir: 'css', file: 'index.css')}" type="text/css">
     <link rel="stylesheet" href="${resource(dir: 'css', file: 'search.css')}" type="text/css">
     <style>
     .ui-searchbar-wrap .ui-searchbar-cancel {
		    color: #bbbbbb;
		    font-size: 16px;
		    padding: 4px 8px;
		}
		.btn-more{
		    color: #A89E9B;
		    padding: 0 15px;
		    font-size: 15px;
		    text-align: center;
		}
		.page-search ul.list-default li {
		    border-radius: 7px;
		}
		@media screen and (-webkit-min-device-pixel-ratio: 2)
		.ui-border-radius:before {
		     border: 0px solid #e0e0e0; 
		}
		::-webkit-search-cancel-button { display: none; }
		-webkit-appearance: none;
     </style>  
    </head>
<body>
     <div class="ui-footer ui-footer-navi ui-btn-group ui-border-t">
      <a id="index" href="/scfire" class="active"><i class="i1"></i><div>首页</div></a>
      <a href="/scfire/project/fundPoolList"><i class="i2"></i><div>爱心池</div></a>
      <a id="project" href="/scfire/project/start"><i class="i3"></i><div>发起项目</div></a>
      <a id="center" href="/scfire/user/userCenter"><i class="i4"></i><div>个人中心</div></a>
    </div>
	<div class="ui-container">
	<div id="wrapper">
	<div class="page-search" data-log="搜索页">
	<div class="header">
	<div class="ui-searchbar-wrap ui-border-b">
    <div class="ui-searchbar ui-border-radius">
        <i class="ui-icon-search"></i>
        <div class="ui-searchbar-text">请输入搜索内容</div>
        <div class="ui-searchbar-input"><input id="search" value="" onfocus="onhit();" onblur="onhit();" type='search' oninput="onhit();"  placeholder="请输入搜索内容" ></div>
        <div id="sclose" class="ui-icon-close"></div>
    </div>
    <button class="ui-searchbar-cancel">取消</button>
    </div>
	</div><!--vue-if-->
	<div id="searchline">
	    <input id="offset" type="hidden" value="1">
	    <input id="sign" type="hidden" value="1">
	    <input id="sear" type="hidden" value="1">
		<ul class="list-default">
		     <li><span><a onclick="signclick('000000');">全部项目</a></span></li>
		     <li><span><a onclick="signclick('100001');">培训活动</a></span></li>
		     <li><span><a onclick="signclick('100002');">教学物资</a></span></li>
		     <li><span><a onclick="signclick('100003');">学术创新</a></span></li>
		     <li><span><a onclick="signclick('梦想中心');">梦想中心</a></span></li>
	     </ul>
	  </div><!--vue-if-->
	  </div><!--v-view-->
	  </div>
	<div>
	</div><!--vue-if--></div><!--v-view--></div>
	 <div class="list" id="showdata">
    </div>
    <div style="text-align: center;margin-bottom: 5px">
    <li>
    	<a id="cz-more" href='javascript:;' class='btn-more' id='week' onclick='nextMore();'>点击加载更多</a>
    	<a id="cz-end" href='javascript:;' class='btn-more' id='week' >已经到底了</a>
     </li>
     </div>
    <script src="/scfire/frozen/js/frozen.js"></script>
	<script type="text/javascript">
	 var flag = IsPC();
     if(flag==true){
    	 $("#index").attr("href","/scfire/index/pc_index/");
         	$("#project").remove();
			$("#center").remove();
			$("#index").attr("href","/scfire/index/pc_index/")
         }
		var finalOffset= 20
		var offset = 0
		var search
		var sign
		$(function(){
			$("#cz-more").hide();
	    	$("#cz-end").hide();
			})
	   $('.ui-searchbar').click(function(){
		   var value=$("#search").val();
			if(value.length==0){
				 $("#searchline").show();
			}
	        $('.ui-searchbar-wrap').addClass('focus');
	        $('.ui-searchbar-input input').focus();
	    });
	    $('.ui-searchbar-cancel').click(function(){
	    	  history.go(-1);
<%--	    	$("#search").val("");--%>
<%--	    	$("#searchline").hide();--%>
<%--	        $('.ui-searchbar-wrap').removeClass('focus');--%>
	    });
	    $('#sclose').click(function(){
	    	$("#search").val("");
	    	$("#searchline").hide();
		    })
	    //ajax请求
	    //搜索请求这里
	  document.onkeydown=function(event){
		var value=$("#search").val();
		if(check(value)==0){
			return false;
			}
		var e = event || window.event || arguments.callee.caller.arguments[0];
		if(e && e.keyCode==8){
			var value=$("#search").val();
			if(value.length==0){
				$("#sclose").hide();
				}
			if(value.length==1){
				 $("#sclose").hide();
				 $("#searchline").show();
			}
		}
		if(e && e.keyCode==13){ // enter 键
		$("#searchline").hide();	
		//要做的事情
			//alert(".....");
			//ajax请求事件
	        var value=$("#search").val();
	        search=value;
			sign=null;
			offset = 0
			$("#showdata").empty();
	        getproject(value,null);
		    }
		}
		//biaoqian
		function signclick(value){
			offset = 0
			$("#searchline").hide();
		    $("#showdata").empty();	
			//要做的事情
				//ajax请求事件
				if(value=="梦想中心"){
					search=value;
					sign=null;
					getproject(value,null);
					}else{
						search=null;
						sign=value;
				    getproject(null,value);
						}
			 }
     function  onhit(){
    	  var value=$("#search").val();
    	  if(value.length>0){
    		  $("#searchline").hide();
    		  $("#sclose").show();
        	  }else{
        		  $("#sclose").hide();
            	  }
         }
     function nextMore(){
    	 getproject(search,sign);
         }
	//防御sql
	  function check(a){
		  fibdn = new Array ("‘","\\","/");
		  i=fibdn.length;
		  j=a.length;
		  for(ii=0;ii<i;ii++){
			  for(jj=0;jj<j;jj++){
				  temp1=a.charAt(jj);
		           temp2=fibdn[ii];
		           if (temp1==temp2){
			            return 0;
			             }
			  }
		  }
		  return 1;
		}
		function getproject(value,sign){
			var html="";
	        var el;
			$.ajax({ 
		    	data:{
			    	search:value,
	    	        sign:sign,
	    	        offset:offset
	    	    } ,
	            type:'get',  
	            dataType:'json',
	            url:'/scfire/project/projectSearch?format=json',         
	            beforeSend:function(){
		            	el=$.loading({
		    		        content:"加载中...",
		    		    });
	                },
	            success:function(data){
		            if(data==null){
		            	$("#searchline").show();
		            	$("#cz-more").hide();
		    	    	$("#cz-end").hide();
			            }
		            if(data.length==0){
		            	$("#cz-more").hide();
		            	$("#cz-end").show();
			            }
		            else{
		            	if(data.length<20){
			            	$("#cz-more").hide();
			            	$("#cz-end").show();
				            }else{
				            	$("#cz-more").show();
				            	$("#cz-end").hide();
					            }
		            	 $.each(data,function(i,project){
		 	          		html+="<a href='/scfire/project/projectDetail?projectid="+project.id+"'>"
		 	          		html+="<div class='item bg2'>"
		 	              	html+="<img class='fl' src='/scfire/project/imgRead?img="+project.img+"'>"  
		 	          		html+="<div class='t'><div class='tn'></div>"
		 	                html+="<div class='tt'><span>"+project.name+"</span></div>"
		 	                html+="<div class='td'>"+project.description+"</div> "
		 	              	html+="<div class='tp'>共 <span style='color:#fb6e50;  font-size: 15px;'>"+project.donatenum+" </span>份爱心"  		
		 	          		html+="</div></div><div class='clear'></div></div>"
		 	          		html+="</a>"
		 	          	  });
			            }
	          	 $("#showdata").append(html);
	          	 el.loading("hide");
	          	 offset +=finalOffset; 
	            },  
	            complete:function(){},
	            error:function(data){
	            	el.loading("hide");
	            	el=$.loading({
	    		        content:"加载失败,请刷新重试",
	    		    });
	            }
		           
		      });  
			}
	</script>
</body>
</html>